package com.foreknow.controller;

import com.foreknow.view.Login;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/**
 * 编写第一个Servlet程序
 * Http协议：它是一种无状态的连接协议
 * 规则:
 * 1.所有的Servlet一定要继承HttpServlet
 * 2.重写父类中的doGet/doPost方法：如果前台向后台发送的是get请求，那么就会调用Servlet中的doGet方法，否则调用doPost
 *3.HttpServletRequest接口：请求对象   HttpServletResponse接口：响应对象
 * String getMethod();
 * String getPathInfo();
 * String getContextPath();
 * String getRequestURI();
 * String getServletPath();
 */

public class FirstServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置从服务器端向客户端返回的内容的类型   MIME类型：text/html
        resp.setContentType("text/html;charset=utf-8");
        //获取打印流用于向网页输出内容
        PrintWriter out = resp.getWriter();
        out.println("<html>");
        out.println("<head><title>first servlet</title></head>");
        out.println("<body>");
        out.println("获取请求方法"+req.getMethod()+"<br>");
        out.println("获取到路径信息"+req.getPathInfo() +"<br>");
        out.println("获取到Application Content"+req.getContextPath()+"<br>");
        out.println("获取到相对路径"+req.getRequestURI()+"<br>");
        out.println("获取到全路径"+req.getRequestURL()+"<br>");
        out.println("获取到Servlet的路径"+req.getServletPath()+"<br>");
        out.println("</body>");
        out.println("</html>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
